<template>
  <div class="container">
    <div class="header">
      <el-form inline class="searchItem">
        <div style="display: flex;">
          绑定计量器具
        </div>
        <div style="display: flex;">
          <el-form-item>
              <el-button
                  size="small"
                  type="primary"
                  @click="bindOnClick"
              >
                <span style="display: flex;">
                    <img class="icon" src="@/assets/image/operation/bindIcon.png" alt="">
                    <span class="bind-txt">绑定</span>
                </span>
              </el-button>
          </el-form-item>
        </div>
      </el-form>
    </div>
    <div class="main">
      <RlTable
          :search="false"
          :is-pagination="true"
          @on-change="loadTableData"
          ref="rlTable"
      >
          <template #default>
              <el-table-column label="序号" type="index" width="80" fixed="left" />
              <el-table-column prop="meterUtensilName" label="计量器具名称" />
              <el-table-column prop="meterUtensilTypeName" label="计量器具类型" />
              <el-table-column prop="person" label="测点数量" />
              <el-table-column fixed="right" label="操作" width="140">
                  <template slot-scope="{ row }">
                      <Operation :rowData="row" />
                  </template>
              </el-table-column>
          </template>
      </RlTable>
    </div>
  </div>
</template>
<script>
import Operation from './components/Operation.vue'
import FormModal from './components/FormModal.vue'
export default {
  components:{
    Operation,
    FormModal
  },
  data(){
    return {
      code: '',
      name: '',
      person: '',
      list: [
        {
          code: '123',
          name: '123',
          person: '123',
        },
      ]
    }
  },
  methods:{
    bindOnClick(){
      new this.$pageModal(
          FormModal,
          {
              props: {
                  title: '绑定计量器具',
                  rowData: this.treeNode,
              },
          },
          (result) => {
              if (result) {
                  if (result.state == 'save') {
                      categoryDeviceBind(
                          Object.assign(result.data, { subitemId: this.treeNode.id })
                      )
                          .then((resultData) => {
                              if (resultData.code == 200) {
                                  this.$message.success(resultData.msg)
                                  const rlTable = this.$refs.rlTable
                                  if(rlTable){
                                    rlTable.onSearchChange()
                                  }
                              }
                          })
                          .catch((err) => {
                              this.$message.error(err)
                          })
                  }
              }
          }
      )
    },
    loadTableData({resolve, params}) {
          resolve({
              records:this.list,
              total:0
          })
      // findPageList({
      //   ...params,
      //   condition:{
      //     code: this.code,
      //     name: this.name,
      //     person: this.person,
      //   }
      // }).then(res => {
      //   if(res.code == '200'){
      //     const resData = res.data || {}
      //     resolve({
      //       records: resData.records || [],
      //       total: resData.total
      //     })
      //   }else{
      //     resolve({
      //         records:[],
      //         total:0
      //     })
      //   }
      // })
    },
  }
}
</script>
<style lang="scss" scoped>
.icon {
    width: 14px;
    height: 14px;
    margin-right: 4px;
}
.bind-txt {
    color: #FFF;
    font-size: 14px;
    line-height: 16px;
    height: 14px;
}
.container {
  color: #fff;
  display: flex;
  flex-direction: column;
  width: 100%;
}
.header {
  height: 36px;
  background-color: #0C2E64;
  padding: 21px 15px;
  display: flex;
  margin-bottom: 15px;
  border-radius: 6px;
  .searchItem {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
}
.main {
  height: calc(100vh - 220px);
  position: relative;
  box-sizing: border-box;
}
::v-deep .el-form-item {
  margin-bottom: 0 !important;
  line-height: 36px !important;
  height: 36px !important;
}
::v-deep .el-form-item__label {
  line-height: 36px !important;
  height: 36px!important;
}
::v-deep .el-form-item__content {
  line-height: 36px !important;
  height: 36px !important;
}
</style>